package com.best.onegous.agreement;

import java.util.List;

import com.best.onegous.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Apps extends Application {

	public static DisplayImageOptions touxiang;
	public static DisplayImageOptions allimg;
	public static DisplayImageOptions yuanimg;
	public static SharedPreferences mySharedPreferences;
	public static SharedPreferences.Editor editor;
	public static ImageLoader imageLoader = ImageLoader.getInstance();

	@Override
	public void onCreate() {
		super.onCreate();
		mySharedPreferences = getSharedPreferences("user",
				Activity.MODE_PRIVATE);
		editor = mySharedPreferences.edit();
		Common.code_id = mySharedPreferences.getString("code_id", "");
		Common.user_id = mySharedPreferences.getString("user_id", "");
		
		
		imageLoader.init(ImageLoaderConfiguration.createDefault(this));
		allimg = new DisplayImageOptions.Builder()
		// .showStubImage(R.drawable.jiazai) // 设置图片下载期间显示的图片
				.showImageForEmptyUri(R.drawable.tupian) // 设置图片Uri为空或是错误的时候显示的图片
				.showImageOnFail(R.drawable.tupian) // 设置图片加载或解码过程中发生错误显示的图片
				.cacheInMemory(true) // 设置下载的图片是否缓存在内存中
				.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		yuanimg = new DisplayImageOptions.Builder()
				.showImageForEmptyUri(R.drawable.tupian) // 设置图片Uri为空或是错误的时候显示的图片
				.showImageOnFail(R.drawable.tupian) // 设置图片加载或解码过程中发生错误显示的图片
				.cacheInMemory(true) // 设置下载的图片是否缓存在内存中
				.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
				.displayer(new RoundedBitmapDisplayer(5)) // 设置成圆角图片
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		touxiang = new DisplayImageOptions.Builder()
				.showImageOnFail(R.drawable.ic_launcher) // 设置图片加载或解码过程中发生错误显示的图片
				.cacheInMemory(true) // 设置下载的图片是否缓存在内存中
				.cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
				.displayer(new RoundedBitmapDisplayer(120)) // 设置成圆角图片
				.bitmapConfig(Bitmap.Config.RGB_565).build();

	}

	/**
	 * 网络判断
	 * 
	 */

	public static boolean isNetworkAvailable(Activity activity) {
		Context context = activity.getApplicationContext();
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		if (connectivityManager == null) {
			return false;
		} else {
			NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();

			if (networkInfo != null && networkInfo.length > 0) {
				for (int i = 0; i < networkInfo.length; i++) {
				
				if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		}
		return false;
	}

}
